// pages/classroom/classroom.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
      imgUrl:[
        {image:'https://sign-face.oss-cn-shanghai.aliyuncs.com/img/Icon/classroom1.png'},
        {image:'https://sign-face.oss-cn-shanghai.aliyuncs.com/img/Icon/classroom2.png'},
        {image:'https://sign-face.oss-cn-shanghai.aliyuncs.com/img/Icon/classroom3.png'},
        {image:'https://sign-face.oss-cn-shanghai.aliyuncs.com/img/Icon/classroom4.jpeg'},
        {image:'https://sign-face.oss-cn-shanghai.aliyuncs.com/img/Icon/classroom5.jpeg'},
        {image:'https://sign-face.oss-cn-shanghai.aliyuncs.com/img/Icon/classroom6.png'}
      ],
      c_title:[],
      c_content:[],
      c_content2:['课程时间'],
      longitude:[],
      latitude:[]
  },
  // '数 据 结 构','操 作 系 统','计 算 机 组 成 原 理','计 算 机 网 络','软 件 需 求 分 析','模 拟 电 子 技 术'
  // 'No. 5 Teaching Building','No. 9 Teaching Building','No. 1 Teaching Building','No. 2 Teaching Building','No. 4 Teaching Building','No. 3 Teaching Building'
  // 118.812221
  //32.076264
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.request({
      method: 'get',
      url: app.globalData.url + 'v1/records/user/'+app.globalData.userInfo.id,
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        //'id':'08f74f90-472f-4e52-acba-81441904870d'
      },
      success (res) {
        console.log(res.data.records)
        let list = []
        for(let i = 0; i < res.data.records.length; i++){
          let temp = {
            locationName: '',
            name: '',
            courseTime: '',
            imgUrl:'',
            courseId: ''
          };
          temp.locationName = res.data.location[i].locationName
          temp.name = res.data.courses[i].name
          temp.courseTime = res.data.courses[i].courseTime
          temp.courseTime = temp.courseTime.split(';')
          temp.courseId = res.data.records[i].courseId
          temp.imgUrl = that.data.imgUrl[i%6].image
          list.push(temp)
        }
        console.log(list)
        that.setData({
          list:list
        })
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //返回上一页
  backlast (){
    wx.navigateBack({
      delta: 1
    })
  },

kc_detail: function(e){
    app.globalData.course = e.currentTarget.dataset.x
    wx.request({
      method:'get',
      url: app.globalData.url + 'v1/records/'+app.globalData.userInfo.id+'/' + app.globalData.course.courseId,
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {},
      success (res) {
        console.log(res)
        app.globalData.records = res.data.records
        console.log(app.globalData.records)
        wx.navigateTo({
          url: '/pages/kc_detail/kc_detail'
        })
      }
    })
  }
})
